﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.OracleClient;
using System.Data;

namespace UFC.DBUtility
{
   public  class OracleDAL
    {
       public static void InsertSyncRecord(string recordid, string type, string status, int issuccess)
       {
           //string strSql = string.Format("DELETE FROM WRITETOERPRECORD WHERE RECORDID='{0}' AND RECORDTYPE='{1}'", recordid, type);
           //OracleHelper.ExecuteSql(strSql );

           string strSql = @"INSERT INTO WRITETOERPRECORD
                            (RECORDDATE, RECORDID, RECORDTYPE, RECORDSTATUS，ISSUCCESS) 
                            VALUES (sysdate, :v_recordid, :v_recordtype, :v_recordstatus, :v_issuccess)";

           OracleParameter[] insertParam = new OracleParameter[4];

           insertParam[0] = new OracleParameter();
           insertParam[0].ParameterName = ":v_recordid";
           insertParam[0].OracleType = OracleType.VarChar;
           insertParam[0].Direction = ParameterDirection.Input;
           insertParam[0].Value = recordid;

           insertParam[1] = new OracleParameter();
           insertParam[1].ParameterName = ":v_recordtype";
           insertParam[1].OracleType = OracleType.VarChar;
           insertParam[1].Direction = ParameterDirection.Input;
           insertParam[1].Value = type;

           insertParam[2] = new OracleParameter();
           insertParam[2].ParameterName = ":v_recordstatus";
           insertParam[2].OracleType = OracleType.VarChar;
           insertParam[2].Direction = ParameterDirection.Input;
           insertParam[2].Value = status;


           insertParam[3] = new OracleParameter();
           insertParam[3].ParameterName = ":v_issuccess";
           insertParam[3].OracleType = OracleType.Number;
           insertParam[3].Direction = ParameterDirection.Input;
           insertParam[3].Value = issuccess;

           int i = OracleHelper.ExecuteSql(strSql, insertParam);
       }

       public static void InsertSyncRecord(string recordid, string type, string status, int issuccess,Boolean isOther)
       {
           //string strSql = string.Format("DELETE FROM WRITETOERPRECORD WHERE RECORDID='{0}' AND RECORDTYPE='{1}'", recordid, type);
           //OracleHelper.ExecuteSql(strSql );

           string strSql = @"INSERT INTO WRITETOERPRECORD
                            (RECORDDATE, RECORDID, RECORDTYPE, RECORDSTATUS，ISSUCCESS) 
                            VALUES (sysdate, :v_recordid, :v_recordtype, :v_recordstatus, :v_issuccess)";

           OracleParameter[] insertParam = new OracleParameter[4];

           insertParam[0] = new OracleParameter();
           insertParam[0].ParameterName = ":v_recordid";
           insertParam[0].OracleType = OracleType.VarChar;
           insertParam[0].Direction = ParameterDirection.Input;
           insertParam[0].Value = recordid;

           insertParam[1] = new OracleParameter();
           insertParam[1].ParameterName = ":v_recordtype";
           insertParam[1].OracleType = OracleType.VarChar;
           insertParam[1].Direction = ParameterDirection.Input;
           insertParam[1].Value = type;

           insertParam[2] = new OracleParameter();
           insertParam[2].ParameterName = ":v_recordstatus";
           insertParam[2].OracleType = OracleType.VarChar;
           insertParam[2].Direction = ParameterDirection.Input;
           insertParam[2].Value = status;


           insertParam[3] = new OracleParameter();
           insertParam[3].ParameterName = ":v_issuccess";
           insertParam[3].OracleType = OracleType.Number;
           insertParam[3].Direction = ParameterDirection.Input;
           insertParam[3].Value = issuccess;

           int i = OracleHelper.ExecuteSql(strSql,true, insertParam);
       }

       /// <summary>
       /// 插入推送其他系统的记录表
       /// add:Wangjh 20221220
       /// </summary>
       /// <param name="para"></param>
       public static void InserOtherSystemRecord(Dictionary<string ,string> para) {
           string strSql = @"insert into WritetoOtherSystem wo (wo.containerid,wo.containername,wo.createdate,wo.issuccess,wo.parentid,wo.productname,
wo.recordtype,wo.sendxml,wo.resxml,wo.workflowstepname,wo.writetoothersystemid,wo.workflowstepid) values ('{0}','{1}',sysdate,{2},'{3}','{4}',
'{5}',:sendxml,:resxml,'{6}',sys_guid(),'{7}')";

           strSql = string.Format(strSql, para["ContainerID"], para["ContainerName"], para["IsSuccess"], para["ParentId"],
               para["ProductName"], para["RecordType"], para["WorkflowStepName"], para.ContainsKey("WorkflowStepId")?para["WorkflowStepId"]:"");

           OracleParameter[] insertParam = new OracleParameter[2];

           insertParam[0] = new OracleParameter();
           insertParam[0].ParameterName = ":sendxml";
           insertParam[0].OracleType = OracleType.Clob ;
           insertParam[0].Direction = ParameterDirection.Input;
           insertParam[0].Value = para["SendXml"];

           insertParam[1] = new OracleParameter();
           insertParam[1].ParameterName = ":resxml";
           insertParam[1].OracleType = OracleType.Clob ;
           insertParam[1].Direction = ParameterDirection.Input;
           insertParam[1].Value = para["ResXml"];

            OracleHelper.ExecuteSql(strSql, insertParam);
       }
      
    }
}
